﻿using Admin.NET.Core.Service;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Business.Core.Servive.Auth
{
    /// <summary>
    /// APP登录服务
    /// </summary>
    [ApiExplorerSettings(GroupName = "business")]
    [ApiDescriptionSettings(Order = 500)]
    public class LoginService : IDynamicApiController, ITransient
    {
        private readonly SysAuthService _sysAuthService;

        public LoginService(SysAuthService sysAuthService)
        {
            _sysAuthService = sysAuthService;
        }

        [HttpPost]
        [DisplayName("APP登录")]
        [AllowAnonymous]
        public async Task<LoginOutput> AppLogin([Required] LoginInput input)
        {
            return await _sysAuthService.Login(input);
        }

        /// <summary>
        /// app 获取验证码 🔖
        /// </summary>
        /// <returns></returns>
        [AllowAnonymous]
        [SuppressMonitor]
        [DisplayName("获取验证码")]
        public dynamic APPGetCaptcha()
        {
            return _sysAuthService.GetCaptcha();
        }

        /// <summary>
        /// 获取登陆人信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [DisplayName("获取登陆人信息")]
        public async Task<LoginUserOutput> APPGetUserInfo()
        {
            return await _sysAuthService.GetUserInfo();
        }

        /// <summary>
        /// 退出系统
        /// </summary>
        [DisplayName("退出系统")]
        public void APPLogout()
        {
            _sysAuthService.Logout();
        }
    }
}
